<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         *  递归：在函数内部调用函数自己
         *  
         *  需求：求一个数的阶乘
         *  
         *  5! = 5 * 4!
         *  4! = 4 * 3!
         *  3! = 3 * 2!
         *  2! = 2 * 1!
         *  1! = 1
         * 
         */

        /**
         *  求一个数的阶乘
         */

        function jieCheng(num){
            if(num === 1)  return 1;
            return num * jieCheng(num - 1);
        }

       // jieCheng(5); => 
       // 5 * jieCheng(4) => 
       // 5 * 4 * jieCheng(3) => 
       // 5 * 4 * 3 * jieCheng(2) => 
       // 5 * 4 * 3 * 2 * jieCheng(1);

       console.log(jieCheng(5)); // 5 * 4 * 3 * 2 * 1 = 120
        

    </script>
</body>
</html>